#include "ProfileLogHandler.h"

ProfileLogHandler::ProfileLogHandler()
{
	fout = fopen("log.txt", "w");
}

ProfileLogHandler::~ProfileLogHandler()
{
	fclose(fout);
}
void ProfileLogHandler::BeginOutput(float tTime)
{
	fprintf(fout, "**** Begin Profiler Output ****\n\n");
	fprintf(fout, "  Min :   Avg :   Max :   Time:  # : Profile Name (this loop: %2.5f seconds, %3.1f FPS)\n", tTime, 1.0f/tTime);
	fprintf(fout, "--------------------------------------------\n");
}

void ProfileLogHandler::Sample(float fMin, float fAvg, float fMax, float tAvg, int callCount, string name, int parentCount)
{
	char namebuf[256], indentedName[256];
	char avg[16], min[16], max[16], num[16], time[16];

	sprintf(avg, "%3.1f", fAvg);
	sprintf(min, "%3.1f", fMin);
	sprintf(max, "%3.1f", fMax);
	sprintf(time,"%3.1f", tAvg);
	sprintf(num, "%3d",   callCount);

	strcpy( indentedName, name.c_str());
	for( int indent=0; indent<parentCount; ++indent )
	{
		sprintf(namebuf, " %s", indentedName);
		strcpy( indentedName, namebuf);
	}

	fprintf(fout, "%5s : %5s : %5s : %5s : %3s : %s\n", min, avg, max, time, num, indentedName);
}

void ProfileLogHandler::EndOutput()
{
	fprintf(fout, "\n\n**** End Profiler Output ****\n\n");
}